
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>入库</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body>
		<form id="my_form" style="margin-bottom: 100px;" class="layui-form update_form" action="{:url('shop/goods_add')}" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">商品编码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="goods_no" lay-verify="goods_no" value="{$good.goods_no}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">商品名称</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="goods_name" lay-verify="required" value="{$good.goods_name}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">当前库存</label>
				<div class="layui-input-block update_shurk">
					<input type="text"  lay-verify="required" value="{$good.stock}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">入库</label>
				<div class="layui-input-block update_shurk"  style="width: 180px; margin-right: 10px;">
					<input type="text" name="stock"  placeholder="请输入数量" lay-verify="required"  class="layui-input" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')">
				</div>
				<div class="layui-form-mid layui-word-aux">*请输入数字</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block update_shurk">
					<textarea style="height:80px;" name="memo"   value="{$good.stock}" autocomplete="off" class="layui-input"></textarea>
				</div>
			</div>
			<input type="hidden" name="id" value="{$good.id}">
			<div class="layui-form-item update_btnbox" style="text-align: center;margin-left:unset">
				<div class="layui-input-block" style="max-width: unset;float: unset;">
					<button  type="button" id='change_but' onclick="content_vale()" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
				</div>
			</div>
		</form>
	</body>
</html>
<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/layui/layui.all.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/js/jquery.form.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/js/jquery.qrcode.js"></script>

<script>
	
	
    
    function keyup(obj) {
	obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
	obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
	obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
	obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}
    
    function keyups(obj) {
    	var sale_price = $('#sale_price').val();
    	if(parseFloat(sale_price)<parseFloat(obj.value)){
    		obj.value = sale_price;
    	}
    	
	obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
	obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
	obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
	obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}
    function content_vale(){
    	$("#content").val(editor1.txt.html());
    }
    
    //提交表单
	function set_content(){
  		 $.ajax({
             	type:"post",
                url:"{:url('shop/ruku')}",
                data: $('#my_form').serialize(),//表单数据
                success:function(data){
                    if(data.code==200){
                    	layer.msg('操作成功', {
						  icon: 1,
						  time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							window.parent.location.reload();
							var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
					       	parent.layer.close(index); 
						});
                    }else{
                    	layer.msg('操作失败！');//保存成功提示
                    }
                },error:function(data){
                	var a = data;
                }
        });
  		
  	}
	
	
	//图片上传
	layui.use(['form','upload'], function(){
  		var $ = layui.jquery,upload = layui.upload,form = layui.form;
  		
  		
  		//普通图片上传
		var uploadInst = upload.render({
			elem: '#test1'
		    ,auto: false //选择文件后不自动上传
		    ,choose: function(obj){
			    //将每次选择的文件追加到文件队列
			    var files = obj.pushFile();
			    
			    //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
			    obj.preview(function(index, file, result){
			    	
			    	$('#demo1').attr('src', result); //图片链接（base64）
			    	
			    	html2canvas($('#cut_img'), {
					 onrendered: function (canvas) {
					    var base_url = canvas.toDataURL(); //base64数据
					   	var sendData = base_url.substring(base_url.indexOf(";base64,")+8);
				    	$.post("{:url('agent/shop/upload')}",{value:sendData},function(data){ 
		                            if(data.code == '200'){  
		                            	$('#thumb').val(data.url);
		                            }else{
		                                layer.msg(data.msg);
		                            }
	                    });
					   }
					});
			    });
			}
		    ,url: "{:url('agent/shop/upload')}"
		    ,accept:'images'
		});
	  
		//监听下拉框
		form.on('select(sel_1)', function(data){
			
			var cate_id = data.value;
			
			var cate2_type = platform_2[cate_id];
			var select_htm = '';
			
			if(cate2_type && cate2_type.length<1){
				select_htm = "<option value=''></option>";
			}else{
				for(var i=0;i<cate2_type.length;i++){
					select_htm += "<option value='"+cate2_type[i].id+"'>"+cate2_type[i].type_name+"</option>";
				}
			}
			
			$('#cate2_id').empty();
			$('#cate2_id').append(select_htm);
			form.render('select');
			
			
		});  
	  
	  	//监听提交
		form.on('submit(demo1)', function(data){
			$('#change_but').addClass("layui-btn-disabled");
			set_content();
			
		    return false;
		});
	})
</script>
